package org.dicr.util.data.exc;


/**
 * Data not found exception.
 * 
 * @author <A href='http://dicr.org'>Igor A Tarasov</A>
 * @version 060515
 */
public class NotFoundException extends DataException {
	private static final long serialVersionUID = 1L;

	protected Class<?> objectClass = null;

	protected String objectField = null;

	protected Object fieldValue = null;

	/**
	 * Constructor
	 * 
	 * @param message
	 */
	public NotFoundException(String message) {
		super(message);
	}

	/**
	 * Constructor
	 * 
	 * @param message
	 * @param cause
	 */
	public NotFoundException(String message, Throwable cause) {
		super(message, cause);
	}

	/**
	 * Constructor
	 * 
	 * @param cause
	 */
	public NotFoundException(Throwable cause) {
		super(cause);
	}

	/**
	 * Constructor
	 * 
	 * @param name object name
	 * @param key object key
	 */
	public NotFoundException(String name, Object key) {
		super("not found '" + name + "' with key '" + key + "'");
	}

	/**
	 * Constructor
	 * 
	 * @param clazz data object class
	 * @param field object field
	 * @param value fielf value
	 */
	public NotFoundException(Class<?> clazz, String field, Object value) {
		super("not found '" + clazz.getSimpleName() + "' with " + field + "=" + value);
		this.objectClass = clazz;
		this.objectField = field;
		this.fieldValue = value;
	}

	/**
	 * Constructo
	 * 
	 * @param clazz data object class
	 * @param id value of object id
	 */
	public NotFoundException(Class<?> clazz, long id) {
		super(" not found '" + clazz.getSimpleName() + "' with id=" + id);
		this.objectClass = clazz;
		this.objectField = "id";
		this.fieldValue = Long.valueOf(id);
	}

	/**
	 * Return object class
	 * 
	 * @return class of data object
	 */
	public Class<?> getObjectClass() {
		return this.objectClass;
	}

	/**
	 * Return object field
	 * 
	 * @return field of data object, which value if not found
	 */
	public String getObjectField() {
		return this.objectField;
	}

	/**
	 * Return field value
	 * 
	 * @return value of field which was searched
	 */
	public Object getFieldValue() {
		return this.fieldValue;
	}
}
